﻿using System.Windows.Controls;
using System.Windows.Input;

namespace TYControl
{
    public class TYFloatTextBox : TextBox
    {
        public TYFloatTextBox()
        {
            Text = "0";
            PreviewTextInput += TextBox_PreviewTextInput;
        }

        private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            float outf = 0.0f;
            e.Handled = !float.TryParse(Text + e.Text, out outf);
        }
    }

    public class TYDoubleTextBox : TextBox
    {
        public TYDoubleTextBox()
        {
            Text = "0";
            PreviewTextInput += TextBox_PreviewTextInput;
        }

        private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            double outf = 0.0f;
            e.Handled = !double.TryParse(Text + e.Text, out outf);
        }
    }
}